/*
 *****************************************************************************
 * Copyright (C) 2005-2014 UC Mobile Limited. All Rights Reserved
 * File			: ProxyDetectWapper.mm
 *
 * Description	: ProxyDetectWapper
 *
 * Author		: lixm@ucweb.com
 *
 * History		: Creation, 15-1-20, lixm@ucweb.com, Create the file
 ******************************************************************************
 **/

#import "ProxyDetectWapper.h"
//#import "ProxyDetect.h"

@interface  ProxyDetectWapper()

@property(nonatomic) BOOL isUseProxy;
@property(nonatomic) BOOL isWWANNet;
@property(nonatomic) BOOL localProxyFlag;


@end

@implementation ProxyDetectWapper

//-(NSString*)getProxyName
//{
//    std::string _string = ProxyDetect::instance()->getProxyName();
//    return [NSString stringWithCString:_string.c_str() encoding:[NSString defaultCStringEncoding]];
//}
//
//
//-(int) getProxyPort
//{
//    return ProxyDetect::instance()->getProxyPort();
//}

-(BOOL) hasUseProxySetting
{
    
    NSDictionary *proxySettings = NSMakeCollectable([(NSDictionary *)CFNetworkCopySystemProxySettings() autorelease]);
    NSString *markString = @"doodoobird.com";
    
    for (NSString *key in proxySettings) {
        NSLog(@"key: %@ value: %@", key, proxySettings[key]);
    }
    
    NSString *proxyStringOne = [[[proxySettings objectForKey:@"__SCOPED__"]objectForKey:@"en0"] objectForKey:@"HTTPProxy"];
    if([proxyStringOne  rangeOfString:markString].length > 0){
        self.isUseProxy = 1;
    }else {
        self.isUseProxy = 0;
    }
    self.localProxyFlag = self.isUseProxy;
    if (self.isWWANNet) {
        
        [[NSUserDefaults standardUserDefaults] setValue:self.localProxyFlag?@"1":@"0" forKey:@"proxy_flag"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        
        
        return self.isUseProxy;
    }else {
        if (self.isUseProxy == YES) {
            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"wifiDelegateValue"];
        }
        return self.isUseProxy || [[NSUserDefaults standardUserDefaults] boolForKey:@"wifiDelegateValue"];
    }
    
}

@end
